<?php
/*
     Copyright (C)  2012 Sweta ray.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU
    Free Documentation License"
	@license GNU/GPL http://www.gnu.org/copyleft/gpl.html
    Questions for Joomla
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
   
	Questions for Joomla
	Version 0.0.1
	Created date: Sept 2012
	Creator: Sweta Ray
	Email: admin@phpseo.net
	support: support@phpseo.net
	Website: http://www.phpseo.net
*/

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
JHTML::_('behavior.modal');
$app = JFactory::getApplication();
$params = $app->getParams();
$mainpagetitle =  $params->get('mainpagetitle', 'Questions');
$articleid = $params->get('helparticleid', 1);
$document =& JFactory::getDocument();
$document->setTitle($mainpagetitle);
?>

<div style="width:96%;padding:2%;">
<?php if ($this->params->get('show_category_list', 1)) : ?>
<div class="questionbox">
<div style="float:left; width:90%;">
<span style="float:left"><h2>Categories</h2></span><a style="float:right" href="<?php echo JRoute::_('index.php?option=com_questions&view=form&layout=edit') ?>"><img src="components/com_questions/media/ask.png" alt="Ask a Question"> </a>
<div style="width:250px;float:left;">
<form action="<?php echo JRoute::_('index.php');?>" method="post">
<?php
$lang = JFactory::getLanguage();
$upper_limit = $lang->getUpperLimitSearchWord();
$mitemid = $set_Itemid > 0 ? $set_Itemid : JRequest::getInt('Itemid');
$width			= 30;
$maxlength		= $upper_limit;
$text			= htmlspecialchars($params->get('text', JText::_('COM_QUESTIONS_SEARCH')));

			$output = '<input name="searchword" maxlength="'.$maxlength.'"  type="text" size="'.$width.'" value="'.$text.'"  onblur="if (this.value==\'\') this.value=\''.$text.'\';" onfocus="if (this.value==\''.$text.'\') this.value=\'\';" />';
			echo $output;
		?>
	<input type="hidden" name="task" value="search" />
	<input type="hidden" name="option" value="com_search" />
	<input type="hidden" name="areas" value="questions" />
	<input type="hidden" name="Itemid" value="<?php echo $mitemid; ?>" />
</form>
</div>

<?php if ($this->params->get('display_help', 0)) { ?>
<span style="float:right"><h2><a class="modal" href="<?php echo JRoute::_('index.php?option=com_content&view=article&id='.$articleid) ?>"rel="{handler: 'iframe', size: {x: 640, y: 480}}"><img src="components/com_questions/media/help.png" alt="Help"></a></h2></span>
<?php } ?>
</div>
<?php $catarray = $this->getCategories(); 
$count=count($catarray);
foreach($catarray as $category) {
if(isset($category->title) && $category->level==1){
    ?>
	<div class="Box_D">
	<ul class="questions_category"> 
	<h3>
	<a href="<?php echo JRoute::_("index.php?option=com_questions&view=questions&catid=" . $category->id); ?>">
								<?php echo strtoupper($category->title)."(".$this->countCat($category->id).")"; ?>
	</a>
	</h3>
	<?php
	if ($this->params->get('show_subcategory_list', 1)) { 
	if(isset($category->lft) && isset($category->rgt)){
	$nestedcat = $this->nested($category->lft,$category->rgt,2);
	foreach($nestedcat as $nc){
	?>
	<li class="questions_category_li">
	<a href="<?php echo JRoute::_("index.php?option=com_questions&view=questions&catid=" . $nc->id); ?>">
								<?php echo $nc->title."(".$this->countCat($nc->id).")"; ?>
	</a>
	</li>
    <?php } ?>
	<?php
	}
	}
	?>
	</ul>
	</div>
	<?php
	}
} ?>

</div>
<?php endif; ?>
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<h1>
	<?php echo $this->escape($this->params->get('page_heading')); ?>
	<?php 
	
	//Display Category Name with the title
	if ($this->categoryView):
		echo JText::_("COM_QUESTIONS_LBL_HEAD_CATEGORY") . $this->questions[0]->CategoryName;
	endif;
	
	//Display Tag with the title
	if ($this->tag):
		echo JText::_("COM_QUESTIONS_LBL_HEAD_TAG") . $this->tag;
	endif;
	
	?>
</h1>
<?php endif; ?>



<?php

if (isset($this->viewFilteringOptions))
	echo $this->filteringOptions;
 
?>

<div class="questions<?php echo $this->pageclass_sfx; ?>">

	<?php foreach($this->questions as $question): ?>
		<div class="question system-<?php echo ($question->published ? 'published' : 'unpublished');?>">
			
			<div class="container">
			    
				<div class='leftCol'>
				<div>
				<?php 
				$appParams = json_decode(JFactory::getApplication()->getParams());
				if (isset($appParams->display_gravatars) && $appParams->display_gravatars!=0) :{?>
				<?php AvatarHelper::getAvatar($question->email,"questions_gravatar_small",34,0,$question->userid_creator); ?>
				<?php } ?>
				<?php endif; ?>
				</div>
				<div class="user_rank">			
				<?php echo $this->getRank($question->userid_creator); ?>
                </div>
                <div class="questions_star rank<?php echo $this->getId($question->userid_creator); ?>"></div>
				</div>
				<div class='rightCol'>
				<div class="question_data">			
					<h2 class="question_title">
						<a href="<?php echo $question->link; ?>"><?php echo $question->title; ?></a>
					</h2>
					
					<?php /*<h4 class="data"><?php echo JText::_("COM_QUESTIONS_SUBMITTED_BY"); ?> <?php echo ($question->userid_creator ? JFactory::getUser($question->userid_creator)->name : $question->name ); ?> <?php echo JText::_("COM_QUESTIONS_ON_DATE")?> <?php echo JHtml::date($question->submitted); ?>.</h4> */ ?>
					
					<h4><?php echo JText::_("COM_QUESTIONS_SUBMITTED_BY"); ?> <?php /*echo ($this->question->userid_creator ? JFactory::getUser($this->question->userid_creator)->name : $this->question->name); */?>
	<a href= <?php echo JRoute::_("index.php?option=com_questions&view=profiles&id=".$question->userid_creator . "%3A" . JFactory::getUser($question->userid_creator)->name) ?> ><?php echo ($question->userid_creator ? JFactory::getUser($question->userid_creator)->name : $question->name) ?></a>
	
	 <?php echo " On "?> <?php echo JHtml::date($this->question->submitted); ?> 	
					<h4 class="category">
						<?php if ($question->catid): //if category?>
							<?php echo JText::_("COM_QUESTIONS_CATEGORY"); ?>:
							<a href="<?php echo JRoute::_("index.php?option=com_questions&view=questions&catid=" . $question->catid); ?>">
								<?php echo $question->CategoryName; ?>
							</a>
						<?php endif; //endif category?>
					</h4>
					
					<span class="tags">
					<?php 
					if ($question->qtags):
						echo JText::_("COM_QUESTIONS_TAGS") . ": ";
						foreach ($question->qtags as $tag):
						?>
						<span class="tagsitem">
						<a href="<?php echo JRoute::_("index.php?option=com_questions&view=questions&tag=" . $tag); ?>"><?php echo $tag ?></a>
						</span>
					<?php 
						endforeach;
					endif;
					?>
					</span>
					
				</div>
				<?php
				$app = JFactory::getApplication();
				$params = $app->getParams();
				$twitter_login = $params->get('twitter_login', '');
	$twitter_widget = $params->get('twitter_widget', '');

	$small_twitter = $params->get('small_twitter', '');
	$small_facebook = $params->get('small_facebook', '');
	
	$big_twitter = $params->get('big_twitter', '');
	$big_facebook = $params->get('big_facebook', '');
	$big_share_facebook = $params->get('big_share_facebook', '');

	$facebook = $params->get('facebook', '');
	$twitter = $params->get('twitter', '');
	$myspace = $params->get('myspace', '');
	$stumbleupon = $params->get('stumbleupon', '');
	$reddit = $params->get('reddit', '');
	$delicious = $params->get('delicious', '');
	$google = $params->get('google', '');
	$mail = $params->get('mail', '');
	$print = $params->get('print', '');

	$number_of_tweets = $params->get('number_of_tweets', '');
	$show_avatars = $params->get('show_avatars', '');
	$show_timestamps = $params->get('show_timestamps', '');
	$show_hashtags = $params->get('show_hashtags', '');
	
	$shell_background = $params->get('shell_background', '');
	$shell_color = $params->get('shell_color', '');
	$tweets_background = $params->get('tweets_background', '');
	$tweets_color = $params->get('tweets_color', '');
	$tweets_links = $params->get('tweets_links', '');
	
	$icons_size = $params->get('icons_size', '');


	$social_url = JURI::current();

echo '<div class="social_module">';

if ($facebook != "hide" or $twitter != "hide" or $myspace != "hide" or $stumbleupon != "hide" or $reddit != "hide" or $delicious != "hide" or $google != "hide" or $mail != "hide" or $print != "hide") {
	echo <<<EOT

<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>
<div class="addthis_toolbox">
   <div class="custom_images">
EOT;
	if ($facebook == "show") { 
    ?>
		<a class="addthis_button_facebook"><div class="icon<?php echo $icons_size?> facebook<?php echo $icons_size ?>"></div></a>&nbsp; <?php 
	}
	if ($twitter == "show") {
		?>
		<a class="addthis_button_twitter"><div class="icon<?php echo $icons_size?> twitter<?php echo $icons_size ?>"></div></a>&nbsp; <?php 
		}
	if ($myspace == "show") {
		?>
		<a class="addthis_button_myspace"><div class="icon<?php echo $icons_size?> myspace<?php echo $icons_size ?>"></div></a>&nbsp; <?php 
		}
	if ($stumbleupon == "show") {
		?>
		<a class="addthis_button_stumbleupon"><div class="icon<?php echo $icons_size?> stumbleupon<?php echo $icons_size ?>"></div></a>&nbsp; <?php 
		}
	if ($reddit == "show") {
		?>
		<a class="addthis_button_reddit"><div class="icon<?php echo $icons_size?> reddit<?php echo $icons_size ?>"></div></a>&nbsp; <?php
	}
	if ($delicious == "show") {
		?>
		<a class="addthis_button_delicious"><div class="icon<?php echo $icons_size?> delicious<?php echo $icons_size ?>"></div></a>&nbsp; <?php
	}
	if ($google == "show") {
		?>
		<a class="addthis_button_google"><div class="icon<?php echo $icons_size?> google<?php echo $icons_size ?>"></div></a>&nbsp; <?php
		}
	if ($mail == "show") {
		?>
		<a class="addthis_button_email"><div class="icon<?php echo $icons_size?> email<?php echo $icons_size ?>"></div></a>&nbsp; <?php
	}
	if ($print == "show") {
		?>
		<a class="addthis_button_print"><div class="icon<?php echo $icons_size?> print<?php echo $icons_size ?>"></div></a>&nbsp; <?php
	}
	echo <<<EOT
   </div>
</div>

EOT;
}

if ($small_twitter != "hide" or $small_facebook != "hide") {
	echo <<<EOT
<br/>
<div class="addthis_toolbox">
EOT;
	if ($small_facebook == "show"){
		echo '<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>';
	}
	if ($small_twitter == "show"){
		echo '<a class="addthis_button_tweet"></a>';
	}
	echo <<<EOT
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>
<br/>     
EOT;
}

if ($twitter_widget == "show") {

	if (empty($show_avatars)) {
		$show_avatars="false";
	}
	if (empty($show_timestamps)) {
		$show_timestamps="false";
	}
	if (empty($show_hashtags)) {
		$show_hashtags="false";
	}

	echo <<<EOT
<script src="http://widgets.twimg.com/j/2/widget.js" type="text/javascript"></script>
<script type="text/javascript">
new TWTR.Widget({
	version: 2,
	type: 'profile',
	rpp: $number_of_tweets,
	interval: 6000,
	width: 'auto',
	height: 250,
	theme: {
		shell: {
			background: '$shell_background',
			color: '$shell_color'
		},
		tweets: {
			background: '$tweets_background',
			color: '$tweets_color',
			links: '$tweets_links'
		}
	},
	features: {
		scrollbar: false,
		loop: false,
		live: false,
		hashtags: $show_hashtags,
		timestamp: $show_timestamps,
		avatars: $show_avatars,
		behavior: 'all'
	}
}).render().setUser('$twitter_login').start();
</script>
EOT;
}

if ($big_twitter == "show") {
	echo <<<EOT
<a href="http://twitter.com/share" class="twitter-share-button" data-count="vertical">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<br/><br/>
EOT;
}

if ($big_facebook == "show") {
	echo <<<EOT
<iframe src="http://www.facebook.com/plugins/like.php?href=$social_url&amp;layout=standard&amp;show_faces=true&amp;width=150&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:80px;" allowTransparency="true"></iframe>
EOT;
}

if ($big_share_facebook == "show") {
	echo <<<EOT
<a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
<br/><br/>
EOT;
}

?>
			</div>
			
			<?php if (isset($this->viewStats)): ?>		
			<div class="boxes">
				<a href="<?php echo $question->link; ?>">
					<span class="votes"><?php echo $question->votes; ?><br /><span class="label"><?php echo JText::_("COM_QUESTIONS_VOTES")?></span></span>
					<span class="answers"><?php echo $question->answerscount; ?><br /><span class="label"><?php echo JText::_("COM_QUESTIONS_ANSWERS_LOWERCASE")?></span></span>
					<span class="impressions"><?php echo $question->impressions; ?><br /><span class="label"><?php echo JText::_("COM_QUESTIONS_VIEWS")?></span></span>
				</a>
             <div style="clear:both"></div>
			</div>
			</div>
			<?php endif; ?>
			<div style="float:right;">
			<div style="float:left;">
			<a href="<?php echo JRoute::_("index.php?option=com_questions&view=reports&layout=edit&qid=".$question->id); ?>"><IMG STYLE="border: none; float:right;" src="<?php echo $this->baseurl ?>/components/com_questions/media/reportit.png" ALT="Report It"></a>
			</div>
			<div style="float:left;">
			<a href="<?php echo $question->link; ?>"><IMG STYLE="border: none; float:right;" src="<?php echo $this->baseurl ?>/components/com_questions/media/answerthis.png" ALT="Answer This"></a>
			</div>
			</div>
		</div>
	</div>
	<?php endforeach; ?>
	<div class="pagination_new">
		<p class="counter">
			<?php echo $this->pagination->getPagesCounter(); ?>
		</p>
		<?php echo $this->pagination->getPagesLinks(); ?>
	</div>
    <?php /**********Kindly dont remove this credit. For getting any support from us this link should be intact************/ ?>
    
</div>	
</div>

<p style="text-align:right;"><small>Proudly Powered by </small><a target="_blank" href="http://phpseo.net/">PHP SEO</a></p>